"""
@author RansySun
@create 2019-12-04-19:59
"""
from rest_framework import serializers
from . import models


class TeacherCourseModelSerializer(serializers.ModelSerializer):
    # 老师信息
    class Meta:
        model = models.Teacher
        fields = (
            "name",
            "role",
            "title",
            "signature",
            "image",
            "brief",
        )


class FreeCourseModelSerializer(serializers.ModelSerializer):
    # 免费课程信息
    # 子序列化
    teacher = TeacherCourseModelSerializer()

    # 免费课程
    class Meta:
        model = models.Course
        fields = (
            'id',
            "name",
            "course_img",
            "period",
            "brief",
            "level_name",
            "students",
            "sections",
            "price",
            "teacher",
            "section_list",
            "course_category"
        )


class CategoriesModelSerializer(serializers.ModelSerializer):
    # 分类列表
    class Meta:
        model = models.CourseCategory
        fields = ("id", "name",)


class CourseSectionModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.CourseSection
        fields = '__all__'


class CourseChapterModelSerializer(serializers.ModelSerializer):
    # 子序列，获取当前章节课时的信息
    coursesections = CourseSectionModelSerializer(many=True)

    # 课程章节信息
    class Meta:
        model = models.CourseChapter
        fields = (
            'id',
            'name',
            'chapter',
            'summary',
            'coursesections',
        )
